using System;
using System.ComponentModel;

namespace teavch.Utilities.Electrical.Design.Gui.LineDiagram
{
	public partial class AcGenerator : ElectricalSymbol
	{

		private float _handRatio = .5f;
		private SymbolDirection _direction = SymbolDirection.Top;

		public AcGenerator()
		{
			InitializeComponent();
		}
		
		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the link line ration of the symbol" )]
		public float HandRatio
		{
			get { return this._handRatio; }
			set
			{
				this._handRatio = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the link line direction of the symobole" )]
		public SymbolDirection Direction
		{
			get { return this._direction; }
			set
			{
				this._direction = value;
				this.Refresh();
			}
		}

		protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
		{
			base.OnPaint( e );
			this.Paint( e );
		}

		protected override void OnResize(EventArgs e)
		{
			base.OnResize(e);
			ResizeNow(e);
		}

		private void ResizeNow(EventArgs ea)
		{
			this.Refresh();
		}

		private new void Paint(System.Windows.Forms.PaintEventArgs pea)
		{
			System.Drawing.Pen _pen = System.Drawing.Pens.Lime;
			System.Drawing.Brush _brush = System.Drawing.Brushes.Lime;
			System.Drawing.Drawing2D.PathGradientBrush _gBrush = null;
			System.Drawing.Drawing2D.GraphicsPath _gpath = new System.Drawing.Drawing2D.GraphicsPath();

			float c1x1 = 0, c1y1 = 0, c1size = 0;
			float l1x1 = 0, l1y1 = 0, l1x2 = 0, l1y2 = 0;
			c1size = this.SymbolSize;

			if ( this._direction == SymbolDirection.Top )
			{
				l1x1 = c1size / 2;
				l1y1 = 0;
				l1x2 = l1x1;
				l1y2 = c1size * this._handRatio;
				c1x1 = 0;
				c1y1 = l1y2;
				this.Height = ( int ) Math.Ceiling( c1y1 + c1size + 1 );
				this.Width = ( int ) Math.Ceiling( c1size + 1 );
			}
			else if ( this._direction == SymbolDirection.Left )
			{
				l1x1 = 0;
				l1y1 = c1size / 2;
				l1x2 = c1size * this._handRatio;
				l1y2 = l1y1;
				c1x1 = l1x2;
				c1y1 = 0;
				this.Height = ( int ) Math.Ceiling( c1size + 1 );
				this.Width = ( int ) Math.Ceiling( c1x1 + c1size + 1 );
			}
			else if ( this._direction == SymbolDirection.Bottom )
			{
				l1x1 = c1size / 2;
				l1y1 = c1size;
				l1x2 = l1x1;
				l1y2 = l1y1 + ( c1size * this._handRatio );
				c1x1 = 0;
				c1y1 = 0;
				this.Height = ( int ) Math.Ceiling( ( c1size * this._handRatio ) + c1size + 1 );
				this.Width = ( int ) Math.Ceiling( c1size + 1 );
			}
			else if ( this._direction == SymbolDirection.Right )
			{
				l1x1 = c1size;
				l1y1 = c1size / 2;
				l1x2 = l1x1 + ( c1size * this._handRatio );
				l1y2 = l1y1;
				c1x1 = 0;
				c1y1 = 0;
				this.Height = ( int ) Math.Ceiling( c1size + 1 );
				this.Width = ( int ) Math.Ceiling( c1size + ( c1size * this._handRatio ) + 1 );
			}

			_gpath.AddArc(c1x1, c1y1, c1size, c1size, 0, 360);

			if (this.Fill == true)
			{
				_gBrush = new System.Drawing.Drawing2D.PathGradientBrush(_gpath);
				_gBrush.CenterColor = this.Parent.BackColor;
				_gBrush.SurroundColors = new System.Drawing.Color[] { this.State == SymbolState.On ? System.Drawing.Color.Red : System.Drawing.Color.Lime };
				_gBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipY;
				pea.Graphics.FillPath(_gBrush, _gpath);
			}
			_gpath.CloseFigure();
			_gpath.AddLine(l1x1, l1y1, l1x2, l1y2);
			pea.Graphics.DrawPath(this.Pen, _gpath);

		}

	}
}
